#include <bits/stdc++.h>

int main()
{
    int n = 10, m = 3;
    std::list<int> node;
    for(int i = 1; i <= n; i++)node.push_back(i);
    std::list<int>::iterator it = node.begin();
    while(node.size()>1)
    {
        for(int i = 1; i < m; i++)
        {
            it++;
            if(it == node.end())it = node.begin();
        }
        std::cout<< *it<< " ";
        std::list<int>::iterator next = ++it;
        if(next == node.end())next = node.begin();
        node.erase(--it);
        it = next;
    }
    std::cout<< *it;
    return 0;
}